﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE= Skynet.BusinessEntities;  
using WE= Skynet.WebFoundation.Model;
using System.Collections;
namespace Skynet.WebFoundation.Translators
{
    public  class ExamCategoryTranslator : Infrastructure.Aspect.Services.Traslator.EntityMapperTranslator<BE.ExamCategory, WE.ExamCategory>
    {
        protected override WE.ExamCategory BusinessToService(Infrastructure.Aspect.Services.Traslator.IEntityTranslatorService service, BE.ExamCategory value)
        {
            var res = new WE.ExamCategory();
            res.Id = value.Id;
            res.Title = value.Title;
            res.Description = value.Description;
            return res; 
        }
        protected override BE.ExamCategory ServiceToBusiness(Infrastructure.Aspect.Services.Traslator.IEntityTranslatorService service, WE.ExamCategory value)
        {
            var res = new BE.ExamCategory();
            res.Id = value.Id;
            res.Title = value.Title;
            res.Description = value.Description;
            return res; 
        }
    }
    public class ExamCategoriesTranslator : Infrastructure.Aspect.Services.Traslator.EntityMapperTranslator<IEnumerable<BE.ExamCategory>, IEnumerable<WE.ExamCategory>>
    {
        public override bool CanTranslate(Type targetType, Type sourceType)
        {
            if (targetType.GetInterface("System.Collections.IEnumerable", false)  != null 
                && sourceType.GetInterface("System.Collections.IEnumerable", false) !=null
                && targetType.IsGenericType == true && sourceType.IsGenericType == true)
            {
                var target = targetType.GetGenericArguments().ElementAt(0);
                var source = sourceType.GetGenericArguments().ElementAt(0);

                var res  = (target== typeof(BE.ExamCategory) && source == typeof(WE.ExamCategory)) || (target == typeof(WE.ExamCategory) && source == typeof(BE.ExamCategory));
                return res; 
               
            }
            return false;
        }
        protected override IEnumerable<WE.ExamCategory> BusinessToService(Infrastructure.Aspect.Services.Traslator.IEntityTranslatorService service, IEnumerable<BE.ExamCategory> value)
        {
            var res = new HashSet<WE.ExamCategory>();
            foreach (var item in value)
            {
                var it = service.Translate<WE.ExamCategory>(item);                
                res.Add(it);                
            }
            return res;  
        }

        protected override IEnumerable<BE.ExamCategory> ServiceToBusiness(Infrastructure.Aspect.Services.Traslator.IEntityTranslatorService service, IEnumerable<WE.ExamCategory> value)
        {
            var res = new HashSet<BE.ExamCategory>();
            foreach (var item in value)
            {
                var it = service.Translate<BE.ExamCategory>(item);
                res.Add(it);
            }
            return res;  
        }
    }
}
